<template>
  <div class="header-container">
    <!-- 左侧区域 -->
    <div class="l-content">
        <el-button @click="handleMenu" icon="el-icon-menu" size="mini"></el-button>
        <!-- 面包屑 -->
        <span class="text">首页</span>
    </div>
    <!-- 右侧区域 -->
    <div class="r-content">
        <el-dropdown @command="handleClick">
            <span class="el-dropdown-link">
                <img class="user" :src="picUrl" alt="">
                <!-- ../assets/images/user.png -->
            </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="center">个人中心</el-dropdown-item>
                <el-dropdown-item command="cancel">退出</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
    </div>
  </div>
</template>

<script>
import { getAdminInfo } from '../api';
export default {
    data(){
        return{
            picUrl:''
        }
    },
    methods:{
        handleMenu(){
            this.$store.commit('collapseMenu')
        },
        handleClick(command){
            if(command === "cancel"){
                console.log('登出账户');
                localStorage.removeItem("token")

                //跳转
                this.$router.push('/login')
            }
            if(command === "center"){
                console.log('个人中心')
                this.$router.push('/Person')
                
            }
        },
        getPicUrl(){
            console.log("getPicUrl")
            // getAdminInfo(ret =>{
            //     console.log(ret)
            //     this.picUrl = ret.data.data.picUrl
            //     console.log("headerPic",this.picUrl)
            // })
            getAdminInfo().then(ret =>{
                console.log('admininfo',ret)
                this.picUrl = ret.data.data.picUrl
            })
        }
    },
    mounted(){
        this.getPicUrl()
    }
}
</script>

<style lang="less" scoped>
.header-container{
    padding: 0 20px;
    background-color: #333;
    height:60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .text{
        color:#fff;
        font-size:14px;
        margin-left: 10px;
    }
    .r-content{
        .user{
            width: 40px;
            height: 40px;
            border-radius: 50%;
        }
    }
}
</style>